﻿//-------------------------------------------------------------------
//	Copyright (c) 2010-2014  Zhirnov Andrey
//	This file is part of the "UX Standard Lib" project.
//	See copyright notice in "UX_STL_Ext.h".
//-------------------------------------------------------------------

#include "CLSampler.h"

namespace UX_STL
{
namespace CLShell
{
	
/*
=================================================
	конструктор
=================================================
*/
	CLSampler::CLSampler(): _pID(null)
	{
	}
	
/*
=================================================
	деструктор
=================================================
*/
	CLSampler::~CLSampler()
	{
	}
	
/*
=================================================
	создать сэмплер
=================================================
*/
	bool CLSampler::Create(cl_addressing::type eAddressing, cl_filter::type eFilter, bool bNormalized)
	{
		cl_int	i_cl_err = 0;

		Destroy();

		CL_CALL_R( _pID = clCreateSampler( CLDEVICE()->Context(), bNormalized, eAddressing, eFilter, &i_cl_err ) );
		return true;
	}
	
/*
=================================================
	удалить сэмплер
=================================================
*/
	void CLSampler::Destroy()
	{
		_ReleaseRef();
		_pID = null;
	}
	
/*
=================================================
	
=================================================
*/
	cl_addressing::type CLSampler::GetAddressing() const
	{
		cl_addressing_mode	ret = 0;
		CL_CALL( cl_int	i_cl_err = clGetSamplerInfo( _pID, CL_SAMPLER_ADDRESSING_MODE, sizeof(ret), &ret, null ) );
		return (cl_addressing::type)ret;
	}
	
	cl_filter::type CLSampler::GetFilter() const
	{
		cl_filter_mode	ret = 0;
		CL_CALL( cl_int	i_cl_err = clGetSamplerInfo( _pID, CL_SAMPLER_FILTER_MODE, sizeof(ret), &ret, null ) );
		return (cl_filter::type)ret;
	}
	
	bool CLSampler::IsNormalized() const
	{
		cl_bool	ret = 0;
		CL_CALL( cl_int	i_cl_err = clGetSamplerInfo( _pID, CL_SAMPLER_NORMALIZED_COORDS, sizeof(ret), &ret, null ) );
		return !!ret;
	}

	
	__UX_CL_RC_IMPL( CLSampler, _pID, Sampler, SAMPLER )
		
//-------------------------------------------------------------------

}	// CLShell
}	// UX_STL